<template>
  <a-row class="grid-demo" style="margin-bottom: 16px" align="center">
    <a-col flex="auto">
      <a-menu
        mode="horizontal"
        :default-selected-keys="['1']"
        @menu-item-click="clickMenu"
        :selected-keys="selectedKeys"
      >
        <a-menu-item
          key="0"
          :style="{ padding: 0, marginRight: '38px' }"
          disabled
        >
          <div class="title-bar">
            <img src="@/assets/logo.png" class="logo" />
            <div class="title">OJ判题</div>
          </div>
        </a-menu-item>
        <a-menu-item v-for="item in routes" :key="item.path">{{
          item.name
        }}</a-menu-item>
      </a-menu>
    </a-col>
    <a-col flex="100px">
      {{ store.state.user.loginUser.username || "未登录" }}
    </a-col>
  </a-row>
</template>

<script lang="ts" setup>
import { useStore } from "vuex";
import { routes } from "@/router/routes";
import { useRouter } from "vue-router";
import { ref } from "vue";
import store from "../store";
const router = useRouter();
const route = useRouter();
// 默认选中是首页
const selectedKeys = ref(["/"]);
// 后置路由
router.afterEach((to) => {
  selectedKeys.value = [to.path];
});
const clickMenu = (key: string) => {
  router.push({
    path: key,
  });
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.title-bar {
  display: flex;
  align-items: center;
}

.title {
  color: #444;
  margin-left: 16px;
}

.logo {
  height: 48px;
}
</style>
